Author: Ivan Sharamok
Posted: 12/5/2007 9:42:21 PM
Problem: How to check inherit flag for all descendants in the Security Editor
Amswer: Use the approach described below.
- Create a new class derived from Sitecore.Shell.Framework.Commands.Command and override the Execute method the following way:
using Sitecore.Web.UI.HtmlControls;
using Sitecore.Data.Items;
namespace Custom.Commands
{
class InheritAll : Sitecore.Shell.Framework.Commands.Command
{
public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
{
DataContext dataContext = Sitecore.Context.ClientPage.FindControl("DataContext") as DataContext;
if (dataContext != null)
{
Item currentItem = dataContext.CurrentItem;
InheritItem(currentItem);
}
}
private void InheritItem(Item item)
{
item.Editing.BeginEdit();
item[Sitecore.FieldIDs.InheritSecurity] = "1";
item.Editing.EndEdit();
foreach (Item child in item.GetChildren(Sitecore.Collections.ChildListOptions.IgnoreSecurity))
{
InheritItem(child);
}
}
}
}
Compile this class and move the dll's to the /bin folder of your Sitecore solution.
- Go to Sitecore client and switch to the core database. Go to /sitecore/content/Applications/Security/Security Editor/Ribbon/Home item and create a new Chunk under the item Action. Fill out Header field of the item.
- Create a new Small Button under the newly created Action item. Fill out the Header and Click fields.
Type the following command message in the Click field: security:inheritall and Save all changes.
- Go to the file system and open /App_Config/Commands.config file. Add command message to the file, as shown below:
<!-- Customization InheritAll -->
<command name="security:inheritall" type="Custom.Commands.InheritAll, Commands"/>
Save changes and restart Sitecore.
To see the custom button open the Security Editor and look at the ribbon panel.
Prev Next